<?php 
if(KT!='KhiThe') exit;
class users_model extends khithe_mysql{

	public function getUsers($Username)
	{
		$select = "SELECT * FROM ".users." WHERE `Username`='".$Username."' ";
		$result = parent::SelectMySQL($select);
		parent::CloseConnection();
		return$result; 
	}
	
	public function getUsername($username)
	{
		$Mail = parent::checkStrMySQL($Mail);
		$select = "SELECT * FROM ".users." WHERE Username = '".$username."'";
		$resultSql= parent::SelectMySQL($select);
		$total = mysql_num_rows($resultSql);
		parent::CloseConnection();
		return $total;
	}
	
	public function getMail($Mail)
	{
		$Mail = parent::checkStrMySQL($Mail);
		$select = "SELECT * FROM ".users." WHERE Email = '".$Mail."'";
		$resultSql= parent::SelectMySQL($select);
		$total = mysql_num_rows($resultSql);
		parent::CloseConnection();
		return $total;
	}
	
	public function getUserID($ID){
		
		$ID = parent::checkStrMySQL($ID);
		$select = "SELECT * FROM ".users." WHERE ID = '".$ID."'";
		$result= parent::SelectMySQL($select);
		parent::CloseConnection();
		return $result;
	}
	
	public function updateInsertUser($_POST)
	{
		$ID = parent::checkStrMySQL($_POST['usersID']);
		$Username = parent::checkStrMySQL($_POST['txt_users']);
		$Password = trim($_POST['txt_pass']);
		$Fullname = parent::checkStrMySQL($_POST['txt_Fullname']);
		$Email = parent::checkStrMySQL($_POST['txt_Email']);
		$Y = parent::checkStrMySQL($_POST['txt_Yahoo']);
		$arrY = explode('@',$Y);
		$Yahoo = $arrY[0];
		$Phone = parent::checkStrMySQL($_POST['txt_Phone']);
		$Mobi = parent::checkStrMySQL($_POST['txt_Mobi']);
		$CMND = parent::checkStrMySQL($_POST['txt_CMND']);
		$Address = parent::checkStrMySQL($_POST['txt_Address']);
		
		$pass = $Password==''?"":" `Password`= '".md5($Password)."', ";
		
		if($_POST['acUser']=='edit'){
			$query = "UPDATE ".users." SET Fullname='".$Fullname."', ".$pass." Phone='".$Phone."',Email='".$Email."',YahooChat='".$Yahoo."',Mobi='".$Mobi."',CMND='".$CMND."',Address='".$Address."' WHERE ID = '".trim($ID)."'";
		
		}else if($_POST['acUser']=='add'){
			$query = "INSERT INTO ".users."(Username,`Password`,`Mod`,Fullname,Phone,Email,YahooChat,Mobi,CMND,Address,`Status`)
			VALUES('".$Username."','".md5($Password)."','Customer','".$Fullname."','".$Phone."','".$Email."','".$Yahoo."','".$Mobi."','".$CMND."','".$Address."', 'true')";
		}
		
		parent::CloseConnection();
		return parent::UpdateInsertMySQL($query);
		
	}
}
?>